package com.ldn.server.boot3.starter.config;


import cn.dev33.satoken.interceptor.SaInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 李大牛家的牛 (scafel@163.com)
 * @product serverless
 * @className MyMVCConfig
 * @createDate 2025/4/15 - 9:25
 * @description ToDo...
 **/
@Configuration
public class MyMVCConfig  implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 用于解决跨域问题
        registry.addMapping("/**")
                // 发送cookie
                .allowCredentials(true)
                //设置放行哪些原始域
                .allowedOriginPatterns("*")
                //允许访问的域
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")
                //允许携带请求头的域
                .allowedHeaders("*")
                //允许携带请求参数的域
                .exposedHeaders("*")
                .maxAge(36000);
        WebMvcConfigurer.super.addCorsMappings(registry);
    }

}
